﻿
#include "MainWnd.h"
#include "StringUtil.h"
#include "SelectWnd.h"
#include "DisplayGdi.h"
#include "MatUtil.h"
#include "resource.h"
#include "Dict.h"
#include "PathUtil.h"
#include "CvUtil.h"
#include "ParserUtil.h"
#include <numeric>
#include <objbase.h>

#define CloseButtonControlName _T("BtnClose")
#define MinButtonControlName _T("BtnMin")
#define MaxButtonControlName _T("BtnMax")
#define RestoreButtonControlName _T("BtnRestore")
//////////////////////////////////////////////////////////////////////////
///
DUI_BEGIN_MESSAGE_MAP(CMainWnd, WindowImplBase)
DUI_END_MESSAGE_MAP()

CMainWnd::CMainWnd()
{
	m_savePath = PathUtil::getExecutablePath() + L"\\data\\";
	PathUtil::createPathIfNotExist(m_savePath);
}

CMainWnd::~CMainWnd()
{
}

CControlUI *CMainWnd::CreateControl(LPCTSTR pstrClass)
{
	if (lstrcmpi(pstrClass, _T("PreviewImage" )) == 0)
	{
		return new PreviewImageUI();
	}

	return NULL;
}

void CMainWnd::InitWindow()
{
	SetIcon(IDI_ICON1);
	m_pm.SetDPI(CDPI::GetMainMonitorDPI());

	// 字典
	m_pComboCurrDict = static_cast<CComboUI *>(m_pm.FindControl(_T("combo_curr_dict")));

	m_pEditTestFindRect = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_test_find_rect")));
	m_pEditFindPicName = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_find_pic_name")));
	m_pEditFindPicThreshold = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_find_pic_threshold")));
	m_pEditDictName = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_result_dict_name")));
	m_pEditDictMode = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_dict_mode")));
	m_pEditDictColor = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_dict_color")));
	m_pToleranceEdit = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_tolerance")));
	m_pLabelStatusWindow = static_cast<CLabelUI *>(m_pm.FindControl(_T("label_status_window")));
	m_pLabelStatusSelect = static_cast<CLabelUI *>(m_pm.FindControl(_T("label_status_select")));
	m_pCtrlGetedColor = m_pm.FindControl(_T("ctrl_geted_color"));
	m_pSliderTolerance = static_cast<CSliderUI *>(m_pm.FindControl(_T("slider_tolerance")));

	m_pPreviewImage = static_cast<PreviewImageUI *>(m_pm.FindControl(_T("preview_image")));
	m_pPreviewImage->SetSelectingCallback([this](RECT rc)
										  {
										   CDuiString statusStr;
										   statusStr.Format(L"%d,%d,%d,%d", rc.left,  rc.top, rc.right, rc.bottom);
										   CEditUI *pEditSelectRect = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_select_rect")));
										   pEditSelectRect->SetText(statusStr.GetData()); });
	m_pPreviewImage->SetSelectCompleteCallback([this](RECT rc)
											   { 
												cv::Rect roiRect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
												m_smallDemo = m_cutImg(roiRect);
												HBITMAP hBitmap = MatToHBITMAP(m_smallDemo);
												m_pPreviewSmallDemo->SetBitmap(hBitmap); 
												//触发容差变化，更新结果图
												CalcSmallResult(); });
	m_pPreviewImage->SetGetColorCallback([this](COLORREF color)
										 {
											 m_pCtrlGetedColor->SetBkColor(color);
											 CEditUI *pEditColorValue = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_color_value")));
											 CDuiString szColorValue;
											 szColorValue.Format(_T("#%02X%02X%02X"), GetBValue(color), GetGValue(color), GetRValue(color));
											 pEditColorValue->SetText(szColorValue);
											 CalcSmallResult(); });

	m_pPreviewSmallDemo = static_cast<PreviewImageUI *>(m_pm.FindControl(_T("preview_small_demo")));

	m_pPreviewSmallResult = static_cast<PreviewImageUI *>(m_pm.FindControl(_T("preview_small_result")));

	// 加载字典
	reloadDictList();
}

DuiLib::CDuiString CMainWnd::GetSkinFile()
{
	return _T("main_wnd.xml");
}

LPCTSTR CMainWnd::GetWindowClassName() const
{
	return _T("WdMainClass");
}

UINT CMainWnd::GetClassStyle() const
{
	return CS_DBLCLKS;
}

void CMainWnd::OnFinalMessage(HWND hWnd)
{
	__super::OnFinalMessage(hWnd);
}

void CMainWnd::Notify(TNotifyUI &msg)
{
	CDuiString name = msg.pSender->GetName();
	if (msg.sType == _T("windowinit"))
	{
	}
	else if (_tcsicmp(msg.sType, _T("click")) == 0)
	{
		OnClick(msg.pSender);
	}
	else if (msg.sType == DUI_MSGTYPE_TEXTCHANGED)
	{
		CEditUI *pEdit = (CEditUI *)msg.pSender;
		if (name.CompareNoCase(_T("edit_result_dict_name")) == 0)
		{
			CDuiString dictName = pEdit->GetText();
			if (dictName.IsEmpty())
				return;
			loadDictInfo(dictName.GetData());
		}
		else if (name.CompareNoCase(_T("edit_tolerance")) == 0)
		{
			CDuiString s_tolerance = pEdit->GetText();
			int tolerance = _ttoi(s_tolerance);
			if (tolerance < 0)
				return;
			m_pSliderTolerance->SetValue(tolerance);
			CalcSmallResult();
		}
		else if (name.CompareNoCase(_T("edit_dict_color")) == 0)
		{
			CalcSmallResult();
		}
	}
	else if (msg.sType == DUI_MSGTYPE_SELECTCHANGED)
	{
		CTabLayoutUI *pTabSwitch = static_cast<CTabLayoutUI *>(m_pm.FindControl(_T("tab_swith_left")));
		if (name.CompareNoCase(_T("tab_make_pic")) == 0)
			pTabSwitch->SelectItem(0);
		if (name.CompareNoCase(_T("tab_test")) == 0)
			pTabSwitch->SelectItem(1);
	}
	else if (msg.sType == DUI_MSGTYPE_VALUECHANGED)
	{
		if (_tcsicmp(msg.pSender->GetName(), L"slider_tolerance") == 0)
		{
			CSliderUI *pSlider = (CSliderUI *)msg.pSender;
			int value = pSlider->GetValue();

			CDuiString szValue;
			szValue.Format(_T("%d"), value);
			m_pToleranceEdit->SetText(szValue);

			CalcSmallResult();
		}
	}
	else if (msg.sType == DUI_MSGTYPE_ITEMSELECT)
	{
		if (msg.pSender == m_pComboCurrDict)
		{
			int index = m_pComboCurrDict->GetCurSel();
			if (index == -1)
				return;
			CDuiString dictName = m_pComboCurrDict->GetText();
			loadDictInfo(dictName.GetData());
		}
	}
	return WindowImplBase::Notify(msg);
}
void CMainWnd::OnClick(CControlUI *pSender)
{
	if (_tcsicmp(pSender->GetName(), MinButtonControlName) == 0)
	{
		SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);

		return;
	}
	else if (_tcsicmp(pSender->GetName(), MaxButtonControlName) == 0)
	{
		SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
		return;
	}
	else if (_tcsicmp(pSender->GetName(), RestoreButtonControlName) == 0)
	{
		SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0);
		return;
	}
	else if (_tcsicmp(pSender->GetName(), CloseButtonControlName) == 0)
	{
		Close();
		// PostQuitMessage(0);
		//::ShowWindow(m_hWnd, SW_HIDE);
	}
	else if (_tcsicmp(pSender->GetName(), _T("btn_select_window")) == 0)
	{
		ShowWindow(SW_HIDE);
		SelectWnd::StartCapture([this](HWND hwnd)
								{
									CDuiString statusStr;
									TCHAR titleBuf[256] = {0};
									GetWindowTextW(hwnd, titleBuf, 256);
									RECT rc;
									GetWindowRect(hwnd, &rc);
									statusStr.Format(L"窗口句柄: 0x%08X, 标题: %s, 宽高: %d, %d", hwnd, titleBuf, rc.right - rc.left, rc.bottom - rc.top);
									m_pLabelStatusWindow->SetText(statusStr.GetData());
									m_selectedHwnd= hwnd; 
									//绑定窗口
									long lRet=0;
									wd.BindWindow((long)m_selectedHwnd, L"dx2", L"normal", L"normal", 0, &lRet);
									if (lRet != 1)
									{
										::MessageBox(m_hWnd, _T("绑定失败"), _T("提示"), MB_OK);
										return;
									}
									wd.SetPath(m_savePath.c_str(),&lRet);
									
									CEditUI *pPicEdit = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_test_window_hwnd")));
									if(pPicEdit)
									{
										CDuiString strHwnd;
										strHwnd.Format(L"0x%08X", hwnd);
										pPicEdit->SetText(strHwnd);
									}
									ShowWindow(SW_SHOW); });
	}
	else if (_tcsicmp(pSender->GetName(), _T("btn_capture")) == 0)
	{
		if (m_selectedHwnd == 0)
			return;
		DisplayGdi display;
		long lRet = display.Bind((long)m_selectedHwnd, RDT_GDI_DX2);
		RECT rc;
		::GetWindowRect(m_selectedHwnd, &rc);
		int ww = rc.right - rc.left;
		int wh = rc.bottom - rc.top;

		display.requestCapture(0, 0, ww, wh, m_cutImg);
		HBITMAP hBitmap = MatToHBITMAP(m_cutImg);
		if (hBitmap)
		{
			m_pPreviewImage->SetBitmap(hBitmap);
		}
	}
	else if (_tcsicmp(pSender->GetName(), _T("btn_select_rect")) == 0)
	{
		m_pLabelStatusSelect->SetText(_T("选择区域: 请开始点击选择区域"));
		m_pPreviewImage->StartSelect();
	}
	else if (_tcsicmp(pSender->GetName(), _T("btn_get_color")) == 0)
	{
		m_pPreviewImage->StartGetColor();
	}
	else if (_tcsicmp(pSender->GetName(), _T("btn_save_pic_file")) == 0)
	{
		CEditUI *pPicEdit = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_result_pic_name")));
		CDuiString strPic = pPicEdit->GetText();
		if (strPic.IsEmpty())
		{
			::MessageBox(m_hWnd, _T("请输入图片名"), _T("提示"), MB_OK);
			return;
		}
		std::wstring strPicName = strPic.GetData();
		if (strPicName.find(L'.') == std::string::npos)
		{
			strPicName += L".png";
		}

		std::wstring save_pic_path = m_savePath + L"pic\\";
		// 创建目录
		PathUtil::createPathIfNotExist(save_pic_path);
		// 保存图片
		bool bRet = CvUtil::imwrite_unicode(save_pic_path + strPicName, m_smallDemo);
		// cv::imwrite(strPicName, m_smallResult);
		::MessageBox(m_hWnd, _T("保存成功"), _T("提示"), MB_OK);
	}
	else if (_tcsicmp(pSender->GetName(), _T("btn_test_find_pic")) == 0)
	{
		CDuiString strPic = m_pEditFindPicName->GetText();
		if (strPic.IsEmpty())
		{
			::MessageBox(m_hWnd, _T("请输入图片名"), _T("提示"), MB_OK);
			return;
		}
		if (strPic.Find(L".png") == std::string::npos)
		{
			strPic += L".png";
		}
		CDuiString strRect = m_pEditTestFindRect->GetText();
		RECT rect = {0, 0, 0, 0};
		if (!ParserUtil::parseRect(strRect.GetData(), rect))
		{
			::MessageBox(m_hWnd, _T("请输入正确的矩形区域"), _T("提示"), MB_OK);
			return;
		}

		CDuiString strThreshold = m_pEditFindPicThreshold->GetText();
		double threshold = 0.8;
		if (!strThreshold.IsEmpty())
		{
			threshold = _wtof(strThreshold.GetData());
		}
		long lRet = 0;
		long x1, y1, x2, y2 = 0;
		long startTime = GetTickCount();
		wd.FindPic(rect.left, rect.top, rect.right, rect.bottom, strPic.GetData(), threshold, &x1, &y1, &x2, &y2, &lRet);
		long endTime = GetTickCount();
		if (lRet == 1)
		{
			std::vector<cv::Rect> rects = {{x1 - rect.left, y1 - rect.top, x2 - x1, y2 - y1}};
			drawTestMat(rects);
			CDuiString msg;
			msg.Format(L"找到图片，坐标(%d,%d,%d,%d), 查找时间:%.3fs", x1, y1, x2, y2, (endTime - startTime) / 1000.0f);
			m_pLabelStatusSelect->SetText(msg.GetData());
		}
	}
	else if (_tcsicmp(pSender->GetName(), _T("btn_save_dict_file")) == 0)
	{
		if (m_smallResult.empty())
		{
			::MessageBoxA(m_hWnd, "请先选择区域生成图片", "提示", MB_OK);
			return;
		}
		CEditUI *pPicEdit = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_result_pic_name")));

		std::wstring tolerance_str = m_pToleranceEdit->GetText();
		std::wstring color_str = m_pEditDictColor->GetText();
		std::wstring mode_str = m_pEditDictMode->GetText();

		std::wstring name = pPicEdit->GetText();

		GUID guid;
		CoCreateGuid(&guid);

		// 将GUID转换为字符串格式
		wchar_t guid_str[64];
		swprintf_s(guid_str, L"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
				   guid.Data1, guid.Data2, guid.Data3,
				   guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
				   guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
		std::wstring res_name = guid_str;
		res_name += L".png";

		std::wstring dc_file = m_pComboCurrDict->GetText();
		std::wstring save_pic_path = m_savePath + dc_file + L"\\";
		// 创建目录
		PathUtil::createPathIfNotExist(save_pic_path);
		// 保存图片
		cv::Mat cropResult = CvUtil::cropBinaryAuto(m_smallResult);
		bool bRet = CvUtil::imwrite_unicode(save_pic_path + res_name, cropResult);

		std::wstring dc_path_str = m_savePath;
		dc_path_str += dc_file;
		dc_path_str += L".json";
		Dict dict;
		dict.loadFromFile(dc_path_str);
		dict.setDictInfo(DictInfo{dc_file, tolerance_str.c_str(), color_str.c_str(), (DictMode)_ttoi(mode_str.c_str())});
		dict.addDict(DictContent{name, res_name});
		if (!dict.saveToFile(dc_path_str))
		{
			MessageBox(m_hWnd, _T("保存失败"), _T("提示"), MB_OK);
		}
	}
	else if (_tcsicmp(pSender->GetName(), _T("btn_dict_name_add")) == 0)
	{

		std::wstring dc_file = m_pEditDictName->GetText();

		std::wstring dc_path_str = m_savePath;
		dc_path_str += dc_file;
		dc_path_str += L".json";

		if (PathUtil::fileExists(dc_path_str))
		{
			MessageBox(m_hWnd, _T("字典已存在"), _T("提示"), MB_OK);
			return;
		}
		Dict dict;
		dict.setDictInfo(DictInfo{dc_file, L"25", L"#FFFFFFFF", DictMode_SingleWord});
		if (!dict.saveToFile(dc_path_str))
		{
			MessageBox(m_hWnd, _T("保存失败"), _T("提示"), MB_OK);
		}
		reloadDictList();
	}

	else if (_tcsicmp(pSender->GetName(), _T("btn_test_find_dict")) == 0)
	{
		CDuiString strDict = m_pComboCurrDict->GetText();
		if (strDict.IsEmpty())
		{
			::MessageBox(m_hWnd, _T("请输入正确的字典名"), _T("提示"), MB_OK);
			return;
		}

		CEditUI *pEditWord = static_cast<CEditUI *>(m_pm.FindControl(_T("edit_find_dict_word")));
		CDuiString strWord = pEditWord->GetText();
		if (strWord.IsEmpty())
		{
			::MessageBox(m_hWnd, _T("请输入正确的字名"), _T("提示"), MB_OK);
			return;
		}

		CDuiString strRect = m_pEditTestFindRect->GetText();
		RECT rect = {0, 0, 0, 0};
		if (!ParserUtil::parseRect(strRect.GetData(), rect))
		{
			::MessageBox(m_hWnd, _T("请输入正确的矩形区域"), _T("提示"), MB_OK);
			return;
		}

		CDuiString strThreshold = m_pEditFindPicThreshold->GetText();
		double threshold = 0.8;
		if (!strThreshold.IsEmpty())
		{
			threshold = _wtof(strThreshold.GetData());
		}

		long lRet = 0;
		long x1, y1, x2, y2 = 0;
		wd.ClearDict(&lRet);
		wd.UseDict(strDict.GetData(), &lRet);
		long startTime = ::GetTickCount();
		wd.FindStr(rect.left, rect.top, rect.right, rect.bottom, strWord.GetData(), threshold, &x1, &y1, &x2, &y2, &lRet);
		long endTime = ::GetTickCount();
		long findTime = endTime - startTime;
		if (lRet == 1)
		{
			std::vector<cv::Rect> rects = {{x1 - rect.left, y1 - rect.top, x2 - x1, y2 - y1}};
			drawTestMat(rects);
			CDuiString msg;
			msg.Format(L"找到字，坐标(%d,%d,%d,%d), 查找时间:%.3fs", x1, y1, x2, y2, findTime / 1000.0f);
			m_pLabelStatusSelect->SetText(msg.GetData());
		}
	}
	else if (_tcsicmp(pSender->GetName(), _T("btn_test_ocr_dict")) == 0)
	{
		CDuiString strDict = m_pComboCurrDict->GetText();
		if (strDict.IsEmpty())
		{
			::MessageBox(m_hWnd, _T("请输入正确的字典名"), _T("提示"), MB_OK);
			return;
		}

		CDuiString strRect = m_pEditTestFindRect->GetText();
		RECT rect = {0, 0, 0, 0};
		if (!ParserUtil::parseRect(strRect.GetData(), rect))
		{
			::MessageBox(m_hWnd, _T("请输入正确的矩形区域"), _T("提示"), MB_OK);
			return;
		}

		CDuiString strThreshold = m_pEditFindPicThreshold->GetText();
		double threshold = 0.8;
		if (!strThreshold.IsEmpty())
		{
			threshold = _wtof(strThreshold.GetData());
		}

		long lRet = 0;
		wd.ClearDict(&lRet);
		wd.UseDict(strDict.GetData(), &lRet);
		std::vector<std::wstring> ocr_results;
		std::vector<cv::Rect> rects;
		long startTime = ::GetTickCount();
		wd.Ocr(rect.left, rect.top, rect.right, rect.bottom, threshold, ocr_results, rects);
		std::wstring ret_str = wd.JointResult(ocr_results);
		long endTime = ::GetTickCount();
		long findTime = endTime - startTime;

		if (!ret_str.empty())
		{
			for (auto &it : rects)
			{
				it.x -= rect.left;
				it.y -= rect.top;
			}
			drawTestMat(rects);
			CDuiString msg;
			msg.Format(L"找到字: %s , 查找时间:%.3fs", ret_str.c_str(), findTime / 1000.0f);
			m_pLabelStatusSelect->SetText(msg.GetData());
		}
	}
}

LRESULT CMainWnd::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL &bHandled)
{
	bHandled = FALSE;

	PostQuitMessage(0);
	return 0;
}

LRESULT CMainWnd::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
	if (uMsg == WM_DESTROY)
	{
		::PostQuitMessage(0L);
		bHandled = TRUE;
		return 0;
	}

	bHandled = FALSE;
	return 0;
}
LRESULT CMainWnd::OnLButtonDown(UINT, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{

	bHandled = FALSE;
	return 0;
}
LRESULT CMainWnd::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
#if defined(WIN32) && !defined(UNDER_CE)
	BOOL bZoomed = ::IsZoomed(m_hWnd);
	LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);
	if (::IsZoomed(m_hWnd) != bZoomed)
	{
		if (!bZoomed)
		{
			CControlUI *pControl = static_cast<CControlUI *>(m_pm.FindControl(MaxButtonControlName));
			if (pControl)
				pControl->SetVisible(false);
			pControl = static_cast<CControlUI *>(m_pm.FindControl(RestoreButtonControlName));
			if (pControl)
				pControl->SetVisible(true);
		}
		else
		{
			CControlUI *pControl = static_cast<CControlUI *>(m_pm.FindControl(MaxButtonControlName));
			if (pControl)
				pControl->SetVisible(true);
			pControl = static_cast<CControlUI *>(m_pm.FindControl(RestoreButtonControlName));
			if (pControl)
				pControl->SetVisible(false);
		}
	}

#else
	return __super::OnSysCommand(uMsg, wParam, lParam, bHandled);
#endif
	return 0;
}

void CMainWnd::CalcSmallResult()
{
	if (m_smallDemo.empty())
	{
		return;
	}
	int nTolerance = m_pSliderTolerance->GetValue();
	std::wstring color_str = m_pEditDictColor->GetText();

	std::wstring ss = color_str;
	std::transform(ss.begin(), ss.end(), ss.begin(), ::towupper);
	unsigned int r = 0, g = 0, b = 0; // 使用unsigned int避免类型问题
	int cnt = swscanf(ss.c_str(), L"#%02X%02X%02X", &r, &g, &b);
	cv::Vec3b targetColor(b, g, r);
	// DWORD color = m_pCtrlGetedColor->GetBkColor();
	// cv::Vec3b targetColor(color & 0xFF, (color >> 8) & 0xFF, (color >> 16) & 0xFF);

	// m_smallResult = MakeColorTransparent(m_smallDemo, targetColor, nTolerance);

	m_smallResult = CvUtil::colorBinary(m_smallDemo, targetColor, nTolerance);

	HBITMAP hBitmap = MatToHBITMAP(m_smallResult);
	if (hBitmap)
	{
		m_pPreviewSmallResult->SetBitmap(hBitmap);
	}
}

void CMainWnd::loadDictInfo(const std::wstring &dictName)
{
	std::wstring save_pic_path = m_savePath + dictName + L".json";
	// save_pic_path += dictName;
	// save_pic_path += L".json";

	Dict dict;
	if (dict.loadFromFile(save_pic_path))
	{
		auto tolerance = dict.dict_info_.tolerance_;
		m_pSliderTolerance->SetValue(_wtoi(tolerance.c_str()));

		m_pToleranceEdit->SetText(tolerance.c_str());

		m_pEditDictColor->SetText(dict.dict_info_.color_.c_str());

		TCHAR wMode[10];
		_itow(dict.dict_info_.mode_, wMode, 10);
		m_pEditDictMode->SetText(wMode);

		CalcSmallResult();
	}
}

void CMainWnd::drawTestMat(const std::vector<cv::Rect> &rects)
{
	cv::Mat mat;
	wd.DrawTestMat(rects, mat);
	HBITMAP hBitmap = MatToHBITMAP(mat);
	if (hBitmap)
	{
		m_pPreviewImage->SetBitmap(hBitmap);
	}
}

void CMainWnd::reloadDictList()
{
	m_pComboCurrDict->RemoveAll();
	std::vector<std::wstring> dictFiles = PathUtil::listFilesInDir(m_savePath);
	for (const auto &dictFile : dictFiles)
	{
		if (dictFile.find(L".json") == std::wstring::npos)
		{
			continue;
		}
		std::wstring dictName = dictFile.substr(0, dictFile.find(L".json"));
		dictName = dictName.substr(dictName.find_last_of(L"\\") + 1);

		CListLabelElementUI *pElement = new CListLabelElementUI();
		pElement->SetText(dictName.c_str());
		m_pComboCurrDict->Add(pElement);
	}
	m_pComboCurrDict->SelectItem(0);
}
